package com.jwthhealth_pub.old.common;

import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.app.App;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

/**
 * 图片加载工具
 * Created by Administrator on 2017/2/21.
 */

public class ImageLoader {
    public static void picasso(String url, ImageView img) {
        Picasso.with(App.mContext).load(url).placeholder(R.mipmap.img_loading).error(R.mipmap.img_error).into(img);
    }

    public static void picasso(String url, ImageView img, int wid, int hei){
        Picasso.with(App.mContext).load(url).placeholder(R.mipmap.img_loading)
                .resize(wid, hei).centerCrop().error(R.mipmap.img_error).into(img);
    }

    public static void picasso(String url, ImageView img, final ProgressBar progressBar) {
        progressBar.setVisibility(View.VISIBLE);
        Picasso.with(App.mContext).load(url).placeholder(R.mipmap.img_loading).error(R.mipmap.img_error).into(img, new Callback() {
            @Override
            public void onSuccess() {
                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void onError() {
                progressBar.setVisibility(View.GONE);
            }
        });
    }

    public static interface ImageLoadListenter{
        void imageLoad(int wid, int hie);
    }

    public static void picasso(String url, final ImageView img, final ImageLoadListenter listenter) {
        Picasso.with(App.mContext).load(url).placeholder(R.mipmap.img_loading).error(R.mipmap.img_error).into(img, new Callback() {
            @Override
            public void onSuccess() {
                listenter.imageLoad(img.getWidth(), img.getHeight());


            }

            @Override
            public void onError() {

            }
        });
    }
}
